Write a function to check if a given number is an Armstrong number using Rust.
Write a function to check if a given number is an Armstrong number using Rust.
318
22-Jun-2023
Aryan Kumar
23-Jun-2023Sure, here is a Rust function to check if a given number is an Armstrong number:
Rust
This function first defines a function called is_armstrong_number that takes a u32 number as input and returns a bool value. The function first calculates the number of digits in the number. Then, it iterates through the number, calculating the sum of the powers of each digit. The sum of the powers is then compared to the original number. If the sum of the powers is equal to the original number, then the number is an Armstrong number.
The main function of the program then calls the is_armstrong_number function with the number 153 as input. The result of the function call is then printed to the console.
To run the program, you can save it as a file called armstrong_number.rs and then compile it using the following command:
Code snippet
Once the program is compiled, you can run it using the following command:
Code snippet
This will print the following output to the console:
Code snippet